package com.atguigu.daijia.common.config.minio;

import com.atguigu.daijia.common.execption.GuiguException;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

//@Component
@Slf4j
public class MinioConfig {

    @Autowired
    MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient(){
        try {
            MinioClient minioClient = MinioClient.builder()
                    .endpoint(minioProperties.getEndpointUrl())
                    .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                    .build();
            return minioClient;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("初始化minio配置异常: 【{}】", e.fillInStackTrace());
        }
    }
}
